<!--
 * @Date: 2024-12-25 19:45:43
 * @LastEditors: Lcx l1556461835@163.com
 * @LastEditTime: 2025-01-21 21:01:42
 * @FilePath: \webprocessdesign\pages\fangzhen\components\prediction.vue
 * @Description: 
-->
<template>
  <div>
    <el-card header="PDI参数">
      <el-form :inline="true" :model="tbProcalcSumDTO" label-position="left" label-width="120px">
        <el-form-item label="钢种" prop="steelGrade">
          <el-select v-model="tbProcalcSumDTO.steelGrade" placeholder="钢种" @change="handleSteelChange">
            <el-option v-for="item in steelList" :key="item.id" :label="item.steelGrade" :value="item.steelGrade"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="成品厚度[mm]" prop="size_product_thk">
          <el-input v-model="tbProcalcSumDTO.size_product_thk" placeholder="成品厚度" @input="(v)=>(tbProcalcSumDTO['size_product_thk'] = v.replace(/[^\d.]/g,''))"></el-input>
        </el-form-item>
        <el-form-item label="出炉温度[℃]" prop="temp_dischg">
          <el-input v-model="tbProcalcSumDTO.temp_dischg" placeholder="出炉温度" @input="(v)=>(tbProcalcSumDTO['temp_dischg'] = v.replace(/[^\d.]/g,''))"></el-input>
        </el-form-item>
        <el-form-item label="FDT[℃]" prop="temp_fdt_avg">
          <el-input v-model="tbProcalcSumDTO.temp_fdt_avg" placeholder="FDT" @input="(v)=>(tbProcalcSumDTO['temp_fdt_avg'] = v.replace(/[^\d.]/g,''))"></el-input>
        </el-form-item>
        <el-form-item label="CT温度[℃]" prop="temp_ct_avg">
          <el-input v-model="tbProcalcSumDTO.temp_ct_avg" placeholder="CT温度" @input="(v)=>(tbProcalcSumDTO['temp_ct_avg'] = v.replace(/[^\d.]/g,''))"></el-input>
        </el-form-item>
      </el-form>
    </el-card>
    <!-- 化学元素 -->
    <el-card style="margin: 10px 0">
      <BasicForm :form-list="huaxueList" :form-info="elementDTO" inline></BasicForm>
    </el-card>

    <!-- 仿真结果 -->
    <el-card v-if="flag == 1" header="仿真结果">
      <el-form :inline="true" :model="result" label-position="left" label-width="120px">
        <el-form-item label="屈服强度" prop="ys_predict">
          <el-input v-model="result.ys_predict" placeholder="屈服强度"></el-input>
        </el-form-item>
        <el-form-item label="抗拉强度" prop="ts_predict">
          <el-input v-model="result.ts_predict" placeholder="抗拉强度" ></el-input>
        </el-form-item>
        <el-form-item label="延伸率" prop="el_predict">
          <el-input v-model="result.el_predict" placeholder="延伸率" ></el-input>
        </el-form-item>
        <el-form-item label="冲击功1" prop="ie_predict1">
          <el-input v-model="result.ie_predict1" placeholder="冲击功1" ></el-input>
        </el-form-item>
        <el-form-item label="冲击功2" prop="ie_predict2">
          <el-input v-model="result.ie_predict2" placeholder="冲击功2" ></el-input>
        </el-form-item>
        <el-form-item label="冲击功3" prop="ie_predict3">
          <el-input v-model="result.ie_predict3" placeholder="冲击功3" ></el-input>
        </el-form-item>
        <el-form-item label="冲击功均值" prop="ie_predict_avg">
          <el-input v-model="result.ie_predict_avg" placeholder="冲击功均值" ></el-input>
        </el-form-item>
      </el-form>
    </el-card>
        <!-- 任务信息 -->
    <el-card header="任务信息" style="margin: 10px 0">
      <el-form :model="tbProcalcSumDTO" :inline="true">
        <el-form-item label="任务名称" prop="name">
          <el-input v-model.trim="tbProcalcSumDTO.name" placeholder="任务名称"></el-input>
        </el-form-item>
        <el-form-item label="提交人" prop="subPerson">
          <el-input v-model.trim="tbProcalcSumDTO.subPerson" placeholder="提交人"></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="note">
          <el-input v-model.trim="tbProcalcSumDTO.note" :rows="5" type="textarea" placeholder="请输入备注"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button v-if="flag !== 1" type="primary" size="small" @click="submit">提交</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import BasicForm from "../components/BasicForm.vue";
import { FceParams } from "@/lib/commonVar.js";
import { post } from "@/lib/Util";
export default {
  components: { BasicForm },
  props: {
    formInfo: {
      type: Object,
      default: () => {}
    },
    flag: {
      type: Number,
      default: 0 // 0 新建, 1 查看, 2 编辑
    }
  },
  data() {
    return {
      tbProcalcSumDTO: {
        versioncode: 1,
        name: "",
        subPerson: "",
        note: ""
      },
      result: {
        ys_predict: "",
        ts_predict: "",
        el_predict: "",
        ie_predict1: "",
        ie_predict2: "",
        ie_predict3: "",
        ie_predict_avg: ""
      },
      huaxueList: FceParams,
      steelList: [],
      elementDTO: {}
    };
  },
  mounted() {
    this.getSteelGrade();
    if (this.flag == 1) {
      this.tbProcalcSumDTO = {
        name: this.formInfo.name,
        subPerson: this.formInfo.subPerson,
        note: this.formInfo.note,
        steelGrade: this.formInfo.steelGrade,
        size_product_thk: this.formInfo.sizeProductThk,
        temp_dischg: this.formInfo.tempDischg,
        temp_fdt_avg: this.formInfo.tempFdtAvg,
        temp_ct_avg: this.formInfo.tempCtAvg,
        calcType: this.formInfo.calcType
      };

      this.elementDTO = {
        c: this.formInfo.c,
        si: this.formInfo.si,
        mn: this.formInfo.mn,
        nb: this.formInfo.nb,
        v: this.formInfo.v,
        ti: this.formInfo.ti,
        cr: this.formInfo.cr,
        mo: this.formInfo.mo
      };

      this.result = {
        ys_predict: this.formInfo.ysPredict,
        ts_predict: this.formInfo.tsPredict,
        el_predict: this.formInfo.elPredict,
        ie_predict1: this.formInfo.iePredict1,
        ie_predict2: this.formInfo.iePredict2,
        ie_predict3: this.formInfo.iePredict3,
        ie_predict_avg: this.formInfo.iePredictAvg
      };
    } else if (this.flag == 2) {
      // 查看模式
      this.tbProcalcSumDTO = {
        name: this.formInfo.name,
        subPerson: this.formInfo.subPerson,
        note: this.formInfo.note,
        steelGrade: this.formInfo.steelGrade,
        size_product_thk: this.formInfo.sizeProductThk,
        temp_dischg: this.formInfo.tempDischg,
        temp_fdt_avg: this.formInfo.tempFdtAvg,
        temp_ct_avg: this.formInfo.tempCtAvg,
        calcType: this.formInfo.calcType
      };

      // 化学元素数据
      this.elementDTO = {
        c: this.formInfo.c,
        si: this.formInfo.si,
        mn: this.formInfo.mn,
        nb: this.formInfo.nb,
        v: this.formInfo.v,
        ti: this.formInfo.ti,
        cr: this.formInfo.cr,
        mo: this.formInfo.mo
      };
    }
  },
  methods: {
    // 查询钢种
    async getSteelGrade() {
      let res = await post("/api/tbChemical/getSteelGrade", {});
      this.steelList = res.data;
    },
    handleSteelChange(val) {
      if (val) {
        let item = this.steelList.filter(item => item.steelGrade == val);
        post(`/api/tbChemical/byIdSelect?id=${item[0].id}`).then(res => {
          this.elementDTO = res.data;
        });
      } else {
        this.$refs.huaRef.resetForm();
      }
    },
    // 提交事件
    submit() {
      this.tbProcalcSumDTO["calcType"] = 7; // 标记这是性能预测
      const data = {
        c: this.elementDTO.c,
        si: this.elementDTO.si,
        mn: this.elementDTO.mn,
        nb: this.elementDTO.nb,
        v: this.elementDTO.v,
        ti: this.elementDTO.ti,
        cr: this.elementDTO.cr,
        mo: this.elementDTO.mo,
        name: this.tbProcalcSumDTO.name,
        note: this.tbProcalcSumDTO.note,
        sizeProductThk: this.tbProcalcSumDTO.size_product_thk,
        steelGrade: this.tbProcalcSumDTO.steelGrade,
        subPerson: this.tbProcalcSumDTO.subPerson,
        tempCtAvg: this.tbProcalcSumDTO.temp_ct_avg,
        tempDischg: this.tbProcalcSumDTO.temp_dischg,
        tempFdtAvg: this.tbProcalcSumDTO.temp_fdt_avg,
        calcType: this.tbProcalcSumDTO.calcType
      };
      post("/api/tbProcalcSum/redictionSave", data).then(res => {
        if (res.code == 200) {
          this.$message({
            message: "提交成功",
            type: "success"
          });
        } else {
          this.$message.error(res.message);
        }
        this.$emit("close");
      });
    }
  }
};
</script>

<style>
</style>
